package smartwiz.client.app.mvp.home;

import java.util.ArrayList;
import java.util.logging.Logger;

import com.google.gwt.user.client.rpc.AsyncCallback;

import smartwiz.client.BudvaServiceAsync;
import smartwiz.client.app.gin.Injector;
import smartwiz.client.app.mvp.admin.AdminMVP;
import smartwiz.client.fwk.BasePresenter;
import smartwiz.client.fwk.Place;
import smartwiz.shared.Apartment;

public class HomePresenter extends BasePresenter<HomeMVP.View> implements HomeMVP.Presenter {

	private static final Logger log = Logger.getLogger(HomePresenter.class.getName());

	private BudvaServiceAsync service;

	public HomePresenter(Place place, HomeMVP.View display, BudvaServiceAsync service) {
		super(place, display);
		this.service = service;
	}

	@Override
	protected void onStart() {
		log.fine("MyProjectsPresenter onStart");
		display.setPresenter(this);
		container.setWidget(display);
		Injector.INSTANCE.getService().getApartments(new AsyncCallback<ArrayList<Apartment>>() {
			
			public void onSuccess(ArrayList<Apartment> result) {
				log.info(":: I got apartments :"+result);
				display.setApartments(result);
			}
			
			public void onFailure(Throwable caught) {
				log.info("## missing aparments");
			}
		});
	}

	public void onAdminLink() {
		Injector.INSTANCE.getPlaceController().goTo(AdminMVP.place());
	}


}
